<template>
  <a-modal
    title="查看工序路线关系表"
    width="80%"
    :visible="visible"
    :confirmLoading="confirmLoading"
    @cancel="handleCancel"
  >
    <template slot="footer">
      <a-button
        type="primary"
        @click="handleCancel">确定</a-button>
    </template>
    <a-spin :spinning="confirmLoading">
      <a-form :form="form">
        <a-form-item v-show="false"><a-input v-decorator="['id']" /></a-form-item>
        <a-form-item
          label="工艺路线id"
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
        >
          <a-select style="width: 100% ; pointer-events: none" placeholder="请选择工艺路线id" v-decorator="['workRouteId', {rules: [{ required: true, message: '请选择工艺路线id！' }]}]">
            <a-select-option v-for="(item,index) in list.routeIdList" :key="index" :value="item.id">{{ item.name }}</a-select-option>
          </a-select>
        </a-form-item>
        <a-form-item
          label="源节点"
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
        >
          <a-select style="width: 100%; pointer-events: none" placeholder="请选择源节点" v-decorator="['source', {rules: [{ required: true, message: '请选择源节点！' }]}]">
            <a-select-option v-for="(item,index) in list.sourceList" :key="index" :value="item.id">{{ item.name }}</a-select-option>
          </a-select>
        </a-form-item>
        <a-form-item
          label="目标节点"
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
        >
          <a-select style="width: 100%; pointer-events: none" placeholder="请选择目标节点" v-decorator="['target', {rules: [{ required: true, message: '请选择目标节点！' }]}]">
            <a-select-option v-for="(item,index) in list.targetList" :key="index" :value="item.id">{{ item.name }}</a-select-option>
          </a-select>
        </a-form-item>
      </a-form>
    </a-spin>
  </a-modal>
</template>

<script>
  import { workRouteList } from '@/api/modular/main/workroute/workRouteManage'
  import { workStepList } from '@/api/modular/main/workstep/workStepManage'
  export default {
    data () {
      return {
        list: {
          routeIdList: [],
          stepIdList: [],
          targetList: []
        },
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 }
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 15 }
        },
        visible: false,
        confirmLoading: false,
        form: this.$form.createForm(this)
      }
    },
    methods: {
      // 初始化方法
      detail (record) {
        this.visible = true
        workRouteList().then(res => {
          this.list.routeIdList = res.data
        })
        workStepList().then(res => {
          this.list.sourceList = res.data
          this.list.targetList = res.data
        })
        setTimeout(() => {
          this.form.setFieldsValue(
            {
              id: record.id,
              workRouteId: record.workRouteId,
              source: record.source,
              target: record.target
            }
          )
        }, 100)
      },
      handleCancel () {
        this.form.resetFields()
        this.visible = false
      }
    }
  }
</script>
